﻿<!--
 Copyright (c) 2014 Regents of the University of Michigan

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<UserControl x:Class="PluginTester.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="630" d:DesignWidth="1036">
    <UserControl.Resources>
        <Style x:Key="isPlanSum" TargetType="Label">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsPlanSum}" Value="True">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsPlanSum}" Value="False">
                    <Setter Property="Visibility" Value="Hidden"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!-- Recent Cases-->
        <GroupBox Grid.Row="0" Header="Recent Cases" Margin="5,5,5,2">
            <Grid>
                <DataGrid Name="dtgRecent" ItemsSource="{Binding RecentPatients}" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="CellOrRowHeader" SelectedItem="{Binding SelectedRecentPatient}" Margin="20,4,20,4" ><!--SelectedCellsChanged="dtgRecent_SelectedCellsChanged">-->
                    <DataGrid.Resources>
                        <Style TargetType="DataGridCell">
                            <Style.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="Background" Value="Transparent"/>
                                    <Setter Property="BorderBrush" Value="Transparent"/>
                                    <Setter Property="Foreground" Value="Black"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Id" Binding="{Binding PatientId}" Width="0.8*"/>
                        <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" Width="0.8*"/>
                        <DataGridTextColumn Header="Courses" Binding="{Binding AllCourses}" Width="*"/>
                        <DataGridTextColumn Header="Plans in Scope" Binding="{Binding AllPlansInScope}" Width="1.3*">
                            <DataGridTextColumn.ElementStyle>
                                <Style>
                                    <Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
                                </Style>
                            </DataGridTextColumn.ElementStyle>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="Plan" Binding="{Binding OpenPlanId}" Width="0.8*"/>
                        <DataGridTemplateColumn>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Name="btnOpen" Content="Open" Click="btnOpen_Click" VerticalAlignment="Center"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Name="btnDelFromHistory" Content="Delete" Click="btnDelFromHistory_Click" VerticalAlignment="Center"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </GroupBox>
        <!-- All Cases -->
        <GroupBox Grid.Row="1" Header="All Cases" Margin="5,5,5,5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="50"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Grid.Column="0" Content="Filter Cases" VerticalAlignment="Center"/>
                <TextBox Grid.Row="0" Grid.Column="1" Name="txtFilter" Text="{Binding Path=Filter, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"/>
                <Button Grid.Row="0" Grid.Column="2" Name="btnFilter" Content="Filter" VerticalAlignment="Center" HorizontalAlignment="Left" Width="70" Margin="20,0,0,0" Click="btnFilter_Click"/>
                <Grid Grid.ColumnSpan="3" Grid.RowSpan="2" Margin="0,43,0,7" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Label Grid.Column="0" Grid.Row="0" Content="Select Patient"/>
                    <!-- Patients -->
                    <DataGrid Grid.Column="0" Grid.Row="1" Name="dtgPatients" ItemsSource="{Binding Patients}" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow" SelectedItem="{Binding SelectedPatient}" SelectedCellsChanged="dtgPatients_SelectedCellsChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" Width="*"/>
                            <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="*"/>
                            <DataGridTextColumn Header="Id" Binding="{Binding PatientId}" Width="*"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <!-- Courses-->
                    <Label Grid.Column="1" Grid.Row="0" Content="Select Courses"/>
                    <ListBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding PatientCourses}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox Name="chkCourses" IsChecked="{Binding IsSelected}" Content="{Binding CourseId}" Checked="chkCourses_Checked" Unchecked="chkCourses_Unchecked"/>
                                <!--<RadioButton GroupName="grmCourses" IsChecked="{Binding IsSelected}" Content="{Binding CourseId}" Checked="RadioButton_Checked"/>-->
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <!-- Plans in Scope-->
                    <StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal">
                        <Label Content="Select Planning Items in Scope"/>
                        <Button Name="btnAllPlansScoped" Content="All" Click="btnAllPlansScoped_Click" Margin="30,0,0,0" VerticalAlignment="Center"/>
                    </StackPanel>
                    <ListBox Grid.Column="2" Grid.Row="1" ItemsSource="{Binding CoursePlanItems}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsInScope, Mode=TwoWay}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked">
                                    <CheckBox.Content>
                                        <StackPanel Orientation="Horizontal">
                                            <Label Content="{Binding pItemId}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                                            <Label Style="{StaticResource isPlanSum}" Content="+" Foreground="Red" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                                        </StackPanel>
                                    </CheckBox.Content>
                                </CheckBox>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <!-- Plans-->
                    <Label Grid.Column="3" Grid.Row="0" Content="Select Opened Planning Item"/>
                    <ListBox Grid.Column="3" Grid.Row="1" ItemsSource="{Binding PlansInScope}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <RadioButton GroupName="grpOpenedPitems" IsChecked="{Binding IsOpened}" Content="{Binding pItemId}" Checked="OpenPatient_Checked" VerticalAlignment="Center"/>
                                    <Label Style="{StaticResource isPlanSum}" Content="+" Foreground="Red" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <!--<TabControl Grid.Column="3" Grid.Row="1">
            <TabItem Header="PlanSetups" Name="tabPlans">
                <ListBox Name="lstPlans" ItemsSource="{Binding PlanSetupIds}"  Margin="5,0,5,0" SelectionChanged="lstPlans_SelectionChanged"/>
            </TabItem>
            <TabItem Header="PlanSums" Name="tabSums">
                <ListBox Name="lstSums" ItemsSource="{Binding PlanSumsIds}"  Margin="5,0,5,0" SelectionChanged="lstSums_SelectionChanged"/>
            </TabItem>
        </TabControl>-->

                    <!-- The Start button-->
                    <Grid Grid.Row="2" Grid.ColumnSpan="4" Name="grdStart">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <ListBox Name="itmScripts" Grid.Column="0" ItemsSource="{Binding Scripts}" HorizontalAlignment="Center">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <RadioButton IsChecked="{Binding IsChecked}" Content="{Binding Description}" GroupName="grpScript"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        <Button Grid.Column="1" Name="btnStart" Content="Start Plugin" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" IsEnabled="False" Click="btnStart_Click" Margin="0,10,0,10"/>
                    </Grid>

                </Grid>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
